package com.demo.scenic.controller;

import com.demo.scenic.common.BaseResponse;
import com.demo.scenic.domain.BookedRecord;
import com.demo.scenic.domain.PatternInfo;
import com.demo.scenic.domain.ScenicBase;
import com.demo.scenic.domain.ScenicPhoto;
import com.demo.scenic.domain.vo.ScenicActivityVo;
import com.demo.scenic.domain.vo.ScenicNameVo;
import com.demo.scenic.domain.vo.ScenicPhotoVo;
import com.demo.scenic.domain.vo.ScenicVo;
import com.demo.scenic.service.BusinessService;
import com.demo.scenic.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Api(tags = "用户端")
@RestController
@RequestMapping("/customer")
@AllArgsConstructor
public class CustomerController {
    private final CustomerService customerService;
    private final BusinessService businessService;

    @GetMapping("/getScenicRandom")
    @ApiOperation(value = "获取推荐景点", notes = "获取推荐景点")
    @RequiresAuthentication
    public BaseResponse getScenicRandom() {
        return customerService.getScenicRandom();
    }
    @GetMapping("/getScenicList")
    @ApiOperation(value = "获取全部景点列表", notes = "获取全部景点列表",response = ScenicBase.class)
    @RequiresAuthentication
    public BaseResponse getScenicList() {
        return customerService.getScenicList();
    }

    @GetMapping("/getScenicIdAndNames")
    @ApiOperation(value = "获取全部景点id和名称", notes = "获取全部景点id和名称",response = ScenicNameVo.class)
    @RequiresAuthentication
    public BaseResponse getScenicIdAndNames() {
        return businessService.getScenicNames();
    }

    @GetMapping("/getActive/{id}")
    @ApiOperation(value = "根据id获取活动", notes = "根据id获取活动,随机获取时id传值为0",response = ScenicActivityVo.class)
    @RequiresAuthentication
    public BaseResponse getActive(@PathVariable Integer id) {
        return customerService.getActive(id);
    }
    @GetMapping("/getScenicPhoto")
    @ApiOperation(value = "获取全部景点相册", notes = "获取全部景点相册",response = ScenicPhotoVo.class)
    @RequiresAuthentication
    public BaseResponse getScenicPhoto() {
        return customerService.getScenicPhoto();
    }

    // 根据id获取景区图片
    @GetMapping("/getScenicPhotoById/{id}")
    @ApiOperation(value = "根据id获取景区图片", notes = "根据id获取景区图片",response = ScenicPhoto.class)
    @RequiresAuthentication
    public BaseResponse getScenicPhotoById(@PathVariable Integer id) {
        return BaseResponse.ok(businessService.getScenicImage(id));
    }

    @PostMapping("/getScenicTicket")
    @ApiOperation(value = "获取景区门票以及预约信息", notes = "获取景区门票以及预约信息")
    @RequiresAuthentication
    public BaseResponse getScenicTicket(@Param("id")Integer id,@Param("date") Date date) {
        return customerService.getScenicById(id,date);
    }
    // 生成订单
    @PostMapping("/addOrder")
    @ApiOperation(value = "生成订单", notes = "生成订单")
    @RequiresAuthentication
    public BaseResponse addOrder(@RequestBody BookedRecord record) {
        return customerService.addOrder(record);
    }

    // 付款
    @GetMapping("/payOrder/{id}")
    @ApiOperation(value = "付款", notes = "付款")
    @RequiresAuthentication
    public BaseResponse payOrder(@PathVariable Integer id) {
        return customerService.payOrder(id);
    }
    // 退票
    @GetMapping("/refundOrder/{id}")
    @ApiOperation(value = "退票", notes = "退票")
    @RequiresAuthentication
    public BaseResponse refundOrder(@PathVariable Integer id) {
        return customerService.refundOrder(id);
    }
    // 根据mobile获取个人订票信息
    @GetMapping("/getBookedRecord/{mobile}")
    @ApiOperation(value = "根据mobile获取个人订票信息", notes = "根据mobile获取个人订票信息")
    @RequiresAuthentication
    public BaseResponse getBookedRecord(@PathVariable String mobile) {
        return customerService.getBookedRecord(mobile);
    }

    // 新增出行人信息
    @PostMapping("/addPartner")
    @ApiOperation(value = "新增出行人信息", notes = "新增出行人信息")
    @RequiresAuthentication
    public BaseResponse addPartner(@RequestBody PatternInfo pattern) {
        return customerService.addPartner(pattern);
    }

    // 编辑出行人信息
    @PostMapping("/editPartner")
    @ApiOperation(value = "编辑出行人信息", notes = "编辑出行人信息")
    @RequiresAuthentication
    public BaseResponse editPartner(@RequestBody PatternInfo pattern) {
        return customerService.editPartner(pattern);
    }

    // 根据id删除出行人信息
    @GetMapping("/deletePartner/{id}")
    @ApiOperation(value = "根据id删除出行人信息", notes = "根据id删除出行人信息")
    @RequiresAuthentication
    public BaseResponse deletePartner(@PathVariable Integer id) {
        return customerService.deletePartner(id);
    }
    // 根据用户id获取出行人信息
    @GetMapping("/getPartner/{mobile}")
    @ApiOperation(value = "根据用户账号获取出行人信息", notes = "根据用户账号获取出行人信息")
    @RequiresAuthentication
    public BaseResponse getPartner(@PathVariable String mobile) {
        return customerService.getPartnerByUserId(mobile);
    }
}
